#----------------------------
# Name: Dawson Curry
# Project: Madlibs.py
# Period: 2
# Start Date: 9/17/2013
# Last Revision Date: 10/4/2013
# Version: 1.0.1
#----------------------------
import os

swearFilter = ["dumb",
               "stupid",
               "retard",
               "hell",
               "shit",
               "fuck",
               "crap",
               "damn",
               "bitch",
               "ass",
               "cock",
               "pussy",
               "asshole",
               "motherfucker",
               "dick",
               "whore",
               "faggot",
               "fag",
               "homo",
               "gay",
               "queer",
               "your mom"
			   "badonkadonk"
               ]

bgColor = '0'
txtColor = 'F'
def displayStartScreen():
    print "Madlibs by Dawson Curry"
    print "Good Luck!"
    raw_input("Press Enter to Continue")
    
def displayEndScreen():
    print "See you later!"
    raw_input("Press Enter to Exit")

def getMenuOption(maxOption):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter Number or Q or C> ")
        option = option.upper()
        for num in range(1, maxOption+1):
            if option == str(num):
                goodOption = True
        if option == 'Q':
            goodOption = True
        elif option == 'C':
            goodOption = True
        if not goodOption:
            print "Please pick a valid option!"
    return option
        
def menu(options):
    print "------Please Select a Story------"
    print " [1] The End of the World"
    print " [2] Once Upon A Time"
    print " [3] The Legend"
    print " [C] Color Change Menu"
    print " [Q] Quit"
    print "----------------------------------"
    option = getMenuOption(options)
    return option
    
def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearFilter:
            goodWord = True
        else:
            print "Naughty player...please be polite."
        if not goodWord:
            print "Try again"
    return word
    
def getNumber(prompt, max = "", min = ""):
    num = ""
    goodNum = False
    while not goodNum:
        isNum = True
        num = raw_input(prompt)
        for character in num:
            if character not in "0123456789":
                isNum = False
        if min != "":
            if isNum:
                if float(num) < min:
                    isNum = False
        if max != "":
            if isNum:
                if float(num) > max:
                    isNum = False
        if isNum:
            goodNum = True
        else:
            print "Not a valid number, try again."
    return num

def getColor(prompt):
    colors = ["black", "blue", "green", "aqua", "purple", "yellow", "bright white", "white", "light red", "red"]
    opt = ""
    goodColor = False
    while not goodColor:
        opt = raw_input(prompt)
        if opt.lower() in colors:
            goodColor = True
    if opt == "black":
        color = '0'
    elif opt == 'blue':
        color = '1'
    elif opt == 'green':
        color = '2'
    elif opt == 'bright white':
        color = 'F'
    elif opt == 'white':
        color = 'F'
    elif opt == 'aqua':
        color = '3'
    elif opt == 'purple':
        color = '5'
    elif opt == 'yellow':
        color = '6'
    elif opt == 'light red':
        color = 'C'
    elif opt == 'red':
        color = '4'
    return color
        
def story1():
    noun1 = getWord("Enter a noun: ")
    person = getWord("A Famous Person: ")
    said = getWord("Another word for said: ")
    place = getWord ("Place: ")
    adjective = getWord ("Adjective: ")
    family = getWord ("Family Member: ")
    island = getWord ("Name an island: ")
    number = getNumber ("A Number between 1 and 10: ",11,0)
    story = "I was walking down the"
    story += " " + noun1 + " "
    story += "when, suddenly,"
    story += " " + person + " "
    story += "ran up to me and"
    story += " " + said + " "
    story += "run for it, the zombies are coming!"
    story += " " + person + " "
    story += "ran to"
    story += " " + place + ". "
    story += "I ran to my"
    story += " " + adjective + " "
    story += "house and yelled for my"
    story += " " + family + ". "
    story += "We escaped and lived in"
    story += " " + island + " "
    story += "for"
    story += " " + number + " "
    story += "years "
    story += "The End"
    print story
    
def story2():
    noun1 = getWord("Enter a noun: ")
    adj1 = getWord("Enter an adjective: ")
    noun2 = getWord("Another noun: ")
    noun3 = getWord("Yet another noun: ")
    place = getWord("Name a country: ")
    verb = getWord("Verb in the past tense: ")
    noun4 = getWord("Guess what? ANOTHER NOUN!: ")
    noun5 = getWord("...Yeah. Another noun. I'm sorry. : ")
    story = "Once upon a"
    story += " " + noun1 + ", "
    story += "There was a "
    story += " " + adj1 + " "
    story += " " + noun2 + " "
    story += "who was in love with a"
    story += " " + noun3 + ". "
    story += "They wished they were in"
    story += " " + place + ". "
    story += "They ran away to"
    story += " " + place + " "
    story += "and"
    story += " " + verb + " "
    story += "happily ever after."
    story += "...Except for when the"
    story += " " + noun4 + " "
    story += "invaded"
    story += " " + place + " "
    story += "but that's another"
    story += " " + noun5 + ". "
    story += "The End. For now..."
    print story
    
def story3():
    color = getWord("Enter a color: ")
    family = getWord("Now a family member: ")
    noun1 = getWord("Enter a noun: ")
    noun2 = getWord("Noun again: ")
    noun3 = getWord("Another noun: ")
    ani = getWord("Animal: ")
    noun4 = getWord("Yeah... another noun: ")
    body = getWord("A body part: ")
    story = "Once, there was a boy in a"
    story += " " + color + " "
    story += "hood who wanted an adventure. So, he took his"
    story += " " + family + "'s "
    story += " " + noun1 + " "
    story += "and set out on an adventure. Soon, he saw a cave in the cave was an old"
    story += " " + noun2 + " "
    story += "who gave him a"
    story += " " + noun3 + ". "
    story += "Now, wielding his"
    story += " " + noun1 + " "
    story += "and"
    story += " " + noun3 + ", "
    story += "he set off to find adventure. He ran into a"
    story += " " + ani + " "
    story += "that spat"
    story += " " + noun4 + ". "
    story += "He was promptly smacked in the"
    story += " " + body + " "
    story += "with a"
    story += " " + noun4 + " "
    story += "and gave up. The End."
    print story
def settings():
    print "Color Options: black, blue, green, aqua, purple, yellow, bright white, white, light red, red."
    txtColor = getColor("Enter text color: ")
    bgColor = getColor("Enter background color: ")
    if txtColor != bgColor:
        os.system("color " + bgColor + txtColor)
def run():
    displayStartScreen()
    choice = ""
    while choice != 'Q':
        choice = menu(3)
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
        elif choice == 'C':
            settings()
        elif choice == 'Q':
            displayEndScreen()
            os.system("color " + bgColor + txtColor)
        else:
            print "Something Awful Ocurred...yell at programmer!"
    exit()
run()